/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.Archive;
import java.sql.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author Eduardo
 */
@Stateless
public class ArchiveDAO extends GeneralDAO<Archive> {

    public Archive searchById(String id) {
        Query q = em.createQuery("SELECT object(a) FROM archive AS a "
                + "  WHERE a.idArchive = :id");
        q.setParameter("id", id);
        List<Archive> resultados = q.getResultList();
        if (resultados == null) {
            return null;  // No encontrado
        } else if (resultados.size() != 1) {
            return null; // No encontrado
        } else {
            return resultados.get(0);  // Devuelve el encontrado
        }
    }

    public List<Archive> buscarTodos() {
        Query q = em.createQuery("SELECT object(a) FROM archive as a");
        return q.getResultList();
    }

    public void insert(Archive archive) {
        Query q = em.createQuery("INSERT INTO archive (idArchive,idMongo,idBranch,tracesValid,tracesInvalid,filePath,loadIni,loadEnd,numberTraces,currentTrace) "
                + " VALUES(?,?,?,?,?,?,?,?,?,?)");
        q.setParameter(1, archive.getIdArchive());
        q.setParameter(2, archive.getIdMongo());
        q.setParameter(3, archive.getIdBranch());
        q.setParameter(4, archive.getTracesValid());
        q.setParameter(5, archive.getTracesInvalid());
        q.setParameter(6, archive.getFilePath());
        q.setParameter(7, archive.getLoadIni());
        q.setParameter(8, archive.getLoadEnd());
        q.setParameter(9, archive.getNumberTraces());
        q.setParameter(10, archive.getCurrentTrace());
        q.executeUpdate();
    }
}
